<script type="text/javascript">
    document.observe("dom:loaded", function() {
       $('patient_first_name').focus();
       $('patient_first_name').select();
    });
    
    function validate() {
        isValid = true;
        var setFocus = false;
        $('error_message').innerHTML = "";
        if ($('patient_first_name').value == '') {
            $('error_message').innerHTML += "The patients first name is a required field<br>";
            new Effect.Highlight($('patient_first_name'), {startcolor:'#E6FCCB', endcolor:'#9ECB64'})
            if (!setFocus) {
                setFocus = true;
                $('patient_first_name').focus();
                $('patient_first_name').select();
            }
            isValid = false;
        }
        if ($('patient_last_name').value == '') {
            $('error_message').innerHTML += "The patients last name is a required field<br>";
            new Effect.Highlight($('patient_last_name'), {startcolor:'#E6FCCB', endcolor:'#9ECB64'})
            isValid = false;
            if (!setFocus) {
                $('patient_last_name').focus();
                $('patient_last_name').select();
            }
        }
        
        if (isValid == false) {
            Effect.Appear('error_messages');
        }
        return isValid;
    }
</script>
<% form_for(@patient,:html=> {:onsubmit=>"return validate();"}) do |f| %>
<div class="bd">
  <div class="the_form">
    <%= f.error_messages %>
    <%=f.label(:first_name, "First Name:")%><%= f.text_field :first_name, :class=>"req_textentry" %><%= image_tag("asterisk_orange.png")%>  <br>
    <%=f.label(:last_name, "Last Name:")%><%= f.text_field :last_name, :class=>"req_textentry" %><%= image_tag("asterisk_orange.png")%><br>
    <%=f.label(:birth_date, "Birth Date:")%><%= f.date_select :birth_date,:start_year => 1900 %><br>
    <%=f.label(:race, "Race:")%><%= select(:patient, :race_id, Race.find(:all).collect {|r| [r.race_description, r.id]}) %><br>
    <%=f.label(:diagnosis, "Diagnosis:")%><%= select(:patient, :diagnosis_id, Diagnosis.find(:all).collect {|d| [d.disease_name, d.id]}) %><br>
  </div>
  <div id="error_messages" class="messages" style="display:none;">
    <div class="error_hd"><%= image_tag("error.png") %>&nbsp;&nbsp;Error</div><div id="error_message"></div>
  </div>
</div>
<div class="ft">
  <%= f.submit "Save", :class=>"button" %>
</div>
<% end %>